package junior.util.address;

import java.util.List;

public class StationScorer implements AddressIndexScorer<Station>{

	@Override
	public long getId(Station data) {
		return data.getStationId();
	}

	@Override
	public double score(Address address, Address matchedAddress, Station data) {
		// 地址中的门牌号
		AddressToken[] roadNumber = address.getTokensOfLevel(AddressTokenLevel.ROAD, AddressTokenLevel.NUBMER);
		if(roadNumber == null){
			return 0;
		}
		double score = 0;
		// 匹配地址中的路名
		List<AddressToken> stationRoads = matchedAddress.getLevelMap().get(AddressTokenLevel.ROAD);
		// 如果路名匹配（含后缀+0.25，不含后缀+0.20)
		if(stationRoads != null){
			for(AddressToken road: stationRoads){
				if(road.getToken().equals(roadNumber[0].getToken())){
					score += 0.25;
					break;
				}else if(road.getPrimary().equals(roadNumber[0].getPrimary())){
					score += 0.2;
					break;
				}
			}
		}
		// 然后是门牌号匹配（+0.75）
		if(data.match(roadNumber[1].getPrimary())){
			score += 0.75;
		}
		return score;
	}

}
